package sg.bigo.like.fastclick;

import android.util.Log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;

@Aspect
public class FastClickUtils {
    private final static String TAG = "FastClickUtils";
    private long oldClickTime = 0L;


    @Around("execution(@sg.bigo.like.fastclick.FastClickAnnotation * *(..))")
    public void aroundFastClick(ProceedingJoinPoint joinPoint) throws Throwable {
        long currentClickTime = System.currentTimeMillis();
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        FastClickAnnotation fastClickAnnotation = methodSignature.getMethod().getAnnotation(FastClickAnnotation.class);
        if (fastClickAnnotation == null) {
            return;
        }
        long threshold = fastClickAnnotation.value();
        Log.d(TAG, "currentClickTime=" + currentClickTime + ", oldClickTime=" + oldClickTime + ", threshold=" + threshold);
        if (currentClickTime - oldClickTime > threshold) {
            Log.d(TAG, "more than threshold, so run the code");
            oldClickTime = currentClickTime;
            joinPoint.proceed();
        } else {
            Log.d(TAG, "less than threshold, do not run the code");
            Log.d(TAG, "aroundFastClick(), joinPoint=" + joinPoint);
        }
    }
}